<template>
	<view>
		<chat @gotoMember="gotoMember" :selectMember='selectMember' :username="username" chatType="chatRoom" :reciveScrollTop="scrollTop"></chat>
	</view>
</template>

<script>
	import chat from "@/comps/chat/chat.vue";
	let disp = require("../../utils/broadcast");
	export default {
		components: {
			chat
		},
		props: {
			
		},
		data() {
			return {
				selectMember:null,
				username: {
					your: "",
				},
				self_id:0,
				/*传递userInfo*/
				scrollTop: {
					top: "",
				},
			}
		},
		
		/*获取字体图标点击*/
		onNavigationBarButtonTap:function(e){
			let username = this.username;
			console.log(username);
			var settingList = {
				myName: username.myName||uni.getStorageSync("myUsername"),
				groupName: username.your,
				roomId: username.groupId 
			};
			var id=this.self_id;
			uni.navigateTo({
				url:"../groupChatView/groupChatView?groupInfo="+JSON.stringify(settingList)+"&id="+id
			});
		},
		onShow(){
			if(getApp().globalData.selectMember){
				this.selectMember = getApp().globalData.selectMember;
				console.log(this.selectMember)
				getApp().globalData.selectMember = null
			}
		},
		onLoad(options) {
			console.log('我的ceshi');
			console.log('options的值',options);
			console.log('myUsername',uni.getStorageSync("myUsername"));
			
			/*设置userInfo的值*/
			let userInfo=options.username;
			let self_id=options.id;
			// let stringInfo= userInfo.replace("\\", "");
			// console.log('userInfo的值',stringInfo);
			// console.log('userInfo的your值',stringInfo.your);
			// console.log('userInfo的your数组的值',stringInfo['your']);
			// if(!stringInfo.indexOf('myName')){
			// 	console.log('进来了执行');
			// 	stringInfo['myName'] = uni.getStorageSync("myUsername");
			// }
			/*这里获取不到userInfo的myName的值*/
			let username = JSON.parse(userInfo);
			
			// let username = uni.getStorageSync("myUsername");
			console.log(username);
			this.username = username;
			this.self_id=self_id;
			uni.setNavigationBarTitle({
				title: username.your
			});
		},
		onUnload(){
			disp.fire("em.chatroom.leave");
		},
		methods: {
			gotoMember(){
				uni.navigateTo({
					url:"/pages/groupChatMembers/groupChatMembers?id="+this.self_id+"&groupId="+this.username.groupId,
				})
			},
			/*获取位置*/
			onPageScroll: function(Object) {
				this.scrollTop.top=Object.scrollTop;
			  //console.log(Object.scrollTop);//实时获取到滚动的值
			},
			onPullDownRefresh: function() {
				console.log('onPullDownRefresh');
				uni.showNavigationBarLoading();
				//这里触发chat组件的getMore方法 --xyliu
				// this.selectComponent('#groupchat').getMore()
				// 停止下拉动作
				uni.hideNavigationBarLoading();
				uni.stopPullDownRefresh();
			},
		}
	}
</script>

<style>

</style>
